using System;
using System.Collections.Generic;
using Sustainalytics.ESG.Entities;
using Sustainalytics.Synchronization.Validation.ValidationRules.Comprehensive;
using Xunit;

namespace Sustainalytics.Synchronization.Validation.Tests
{
    [Trait("Category", "Unit")]

    public class CompanyKeyEsgIssues_should
    {
        private readonly KeyESGIssuesRule _sut = new KeyESGIssuesRule();


        [Fact]
        public void return_throw_Exception()
        {
            CompanyKeyESGIssue fake = new CompanyKeyESGIssue()
            {
                KeyESGIssues = null
            };

            var result = _sut.IsValid(fake, new CompanyKeyESGIssue());
            Assert.False(result);
        }


        [Fact]
        public void return_false_when_company_does_not_have_2_KEI_Issues()
        {
            var fake = new CompanyKeyESGIssue()
            {
                Id = new Guid("908586B6-0838-48F4-815C-E139A311CB35"),
                KeyESGIssues = new List<KeyEsgIssue>(),
            };

            var result = _sut.IsValid(fake, new CompanyKeyESGIssue());
            Assert.False(result);
        }

        [Fact]
        public void return_false_when_company_has_2_KEI_Issues_but_without_comments()
        {
            var fake = new CompanyKeyESGIssue()
            {
                Id = new Guid("908586B6-0838-48F4-815C-E139A311CB35"),
                KeyESGIssues = new List<KeyEsgIssue>
                                                  {
                                                      new KeyEsgIssue { Comment = string.Empty },
                                                      new KeyEsgIssue { Comment = "test" }
                                                  },
            };

            var result = _sut.IsValid(fake, new CompanyKeyESGIssue());
            Assert.False(result);
        }

        [Fact]
        public void return_false_when_company_has_more_than_2_KEI_Issues_but_without_comments()
        {
            var fake = new CompanyKeyESGIssue()
            {
                Id = new Guid("908586B6-0838-48F4-815C-E139A311CB35"),
                KeyESGIssues = new List<KeyEsgIssue>
                                                  {
                                                      new KeyEsgIssue { Comment = string.Empty },
                                                      new KeyEsgIssue { Comment = string.Empty },
                                                      new KeyEsgIssue { Comment = "test" }
                                                  },
            };

            var result = _sut.IsValid(fake, new CompanyKeyESGIssue());
            Assert.False(result);
        }

        [Fact]
        public void return_true_when_company_has_2_KEI_Issues_with_comments()
        {
            var fake = new CompanyKeyESGIssue()
            {
                Id = new Guid("908586B6-0838-48F4-815C-E139A311CB35"),
                KeyESGIssues = new List<KeyEsgIssue>
                                                  {
                                                      new KeyEsgIssue { Comment = "test" },
                                                      new KeyEsgIssue { Comment = "test" }
                                                  },
            };

            var result = _sut.IsValid(fake, new CompanyKeyESGIssue());
            Assert.True(result);
        }
    }
}
